<?php

namespace PhpSeverless\Adapter;

use PhpSeverless\CgiResponseParser;
use PhpSeverless\Request;

class Local implements AdapterInterface
{
    public function handleResponse(string $raw)
    {
        $parser = new CgiResponseParser($raw);
        $header = $parser->getHeaders();
        $body = $parser->getBody();
        $status = $parser->getStatusCode();
    }

    public function handleRequest(array $param = []):  ? Request
    {
        $query = http_build_query($_GET);
        $headers = getallheaders();
        $method = $_SERVER['REQUEST_METHOD'];
        $remote_addr = $_SERVER['REMOTE_ADDR'];
        $uri = $_SERVER['REQUEST_URI'];
        $body = file_get_contents('php://input');

        $request = new Request;

        $request->headers = $headers;
        $request->scheme = 'http';
        $request->script = 'index.php';
        $request->method = $method;
        $request->remote_addr = $remote_addr;
        $request->query_string = $query;
        $request->request_uri = $uri;
        $request->body = $body;

        return $request;
    }
}
